package com.example.wiki.controller;


import com.example.wiki.req.EbookQueryReq;
import com.example.wiki.req.EbookSaveReq;
import com.example.wiki.resp.CommonResp;
import com.example.wiki.resp.EbookQueryResp;
import com.example.wiki.resp.PageResp;
import com.example.wiki.service.EbookService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@Api(tags="电子书的增删改查")
@RestController
@RequestMapping("/ebook")
public class EbookController {


    @Resource
    private EbookService ebookService;


    @ApiOperation("获取电子书及其分类  ")
    @GetMapping("/list")
    public CommonResp list(@Valid EbookQueryReq req){
        CommonResp<PageResp<EbookQueryResp>> resp = new CommonResp<>();


        PageResp<EbookQueryResp> list = ebookService.list(req);
        resp.setMessage("请求电子书列表成功");
        resp.setContent(list);
        return  resp;
    }

    @ApiOperation("保存电子书")
    @PostMapping("/save")
    public  CommonResp save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp = new CommonResp<>();
        ebookService.save(req);
        return  resp;
    }
@ApiOperation("删除电子书")
    @DeleteMapping("/delete/{id}")
    public  CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);
        return  resp;
    }





}
